package com.xiaozhi.processor.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {
	public MyInstantiationAwareBeanPostProcessor(){//[2]. 第二个无参构造方法执行
		System.out.println("MyInstantiationAwareBeanPostProcessor...");
	}// 初始化之前进行后置处理,Spring留给我们给这个组件创建对象的回调。如果自己创建对象,Spring不会给我们创建对象了,用我们自己的
	// 【2】. postProcessBeforeInstantiation第二个执行
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		// 如果我们在这里创建了一个cat2对象,Spring会帮我们创建单实列bean吗？
		System.out.println("MyInstantiationAwareBeanPostProcessor...postProcessBeforeInstantiation=>"+beanClass+"--"+beanName);
		return null;
	}// 【5】. 初始化之后进行处理
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		System.out.println("MyInstantiationAwareBeanPostProcessor...postProcessAfterInstantiation=>"+bean+"--"+beanName);// 返回false属性赋值全部结束
		return true;
	}// 【6】. 使用后置处理器bean的属性值
	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName)
			throws BeansException {
		System.out.println("MyInstantiationAwareBeanPostProcessor...postProcessProperties=>"+bean+"--"+beanName);
		return null;
	}
//	public PropertyValues postProcessPropertyValues(
//			PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
//		System.out.println("MyInstantiationAwareBeanPostProcessor...postProcessProperties");
//		return pvs;
//	}
}